/*swig -nopgcpp -java -package org.gl.demoswig.jni -outdir src/org/gl/demoswig/jni jni/Unix.i*/
/*
%module(directors = 1)  Unix.i
swig -nopgcpp -c++ -java -package org.gl.demoswig.jni -outdir src/org/gl/demoswig/jni jni/Unix.i
*/
/*定义模块名  告诉SWIG文件命名*/
%module Unix
/*插入自定代码,这里包含POSIX操作系统的API*/
%{
#include <unistd.h>
#include "common.h"
#include "test.h"
#include <malloc.h>
#include <string.h>;
%}
%include various.i
/*让SWIG知道 uid_t是什么类型*/
typedef unsigned int uid_t;

/*让SWIG包装getuid函数*/
%inline %{
extern  uid_t getuserid(void){
return 0;};
%}

/*映射输入参数的JAVA数组为char* */
%apply(char *STRING, size_t LENGTH) { (char *str, size_t len) };

%inline %{
void some_func(char *str, size_t len) {
}
%}

/*映射JAVA数组为BYTE* */
%typemap(directorin, descriptor="[B") char *BYTE {
jbyteArray jb = (jenv)->NewByteArray(strlen(BYTE));
(jenv)->SetByteArrayRegion(jb, 0, strlen(BYTE), (jbyte*)BYTE);
$input = jb;
}
%typemap(directorout) char *BYTE {
$1 = 0;
if($input){
$result = (char *) jenv->GetByteArrayElements($input, 0);
if(!$1)
return $null;
}
}
%typemap(javadirectorin) char *BYTE "$jniinput"
%typemap(javadirectorout) char *BYTE "$javacall"



typedef  unsigned int 							ko_uint32_t;
//%inline %{
typedef struct ko_byte_array_s{
	ko_uint32_t 		size;
    char *				BYTE;
}ko_byte_array_t;
//%}
/*让SWIG包装setuserids函数*/
extern  void setuserids(ko_byte_array_t *array);

/*在wrap文件中插入C/c++代码*/
%{
extern  void setuserids(ko_byte_array_t *array){
	LOGI("array[%d]",array->size);
	char *s = (char*)malloc(array->size+1);
	memset(s, 0, array->size+1);
	memcpy(s, array->BYTE, array->size);
	int i =0;
	for (i = 0; i < array->size; ++i) {
		LOGI("char[%d]:%c",i,*((char*)(array->BYTE+i)));
	}
	LOGI("array char*: %s",array->BYTE);
	LOGI("array: %s",s);
	free(s);
}
%}
